package com.qilin.hammer;

class A{
	public synchronized void func(final B b){
		try{
			Thread.sleep(200);
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("Thread 1 waiting for b");
		b.func(null);
		System.out.println("finishing A func...");
	}
	
	
}

class B{
	public synchronized void func(final A a){
		try{
			Thread.sleep(200);
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("Thread 2 waiting for a");
		a.func(null);		
		System.out.println("finishing B func...");
	}
}

public class DeadlockTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		final A a=new A();
		final B b=new B();
		
		new Thread(){
			public void run(){
				a.func(b);
				System.out.println("Thread 1 ends");
			}
		}.start();

		new Thread(){
			public void run(){
				b.func(a);
				System.out.println("Thread 2 ends");
			}
		}.start();
			
	}

}
